import requests
from lxml import etree
import os
session = requests.session()
session.headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36'
}
for i in range(1,10):
    url = "https://www.qqtn.com/tx/dongmantx_%d.html"%i
    resp = session.get(url=url)

    resp.encoding = resp.apparent_encoding  # 自动设置编码

    # 解析html
    tree = etree.HTML(resp.text)

    lis = tree.xpath('//ul[@class="g-gxlist-imgbox"]/li')

    # if not os.path.exists('images'):
    #     os.mkdir('images')

    for li in lis:
        img = li.xpath('./a/img/@src')[0]
        img_name = img.split('/')[-1]
        resp_img = session.get(img)
        with open("C:/Users/admin/Pictures/images/" + img_name, "wb") as f:
            f.write(resp_img.content)

